package p.ithorns.integration.hazelcast.mqtt;


import p.ithorns.framework.core.model.IType;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author: liuhaitao
 * @Date: 2022/8/18 11:23
 * @Description:
 */
public enum LocateType implements IType<Integer> {

    // 休眠
    DEV_SLEEP(0x10, "locate_data"),

    // 状态事件
    DEV_WAKE_UP(0x11, "status_event"),

    //
    SOS(0x13, "dev_config"),
    ;

    private final static Map<Integer, LocateType> MAP = Arrays.stream(LocateType.values())
            .collect(Collectors.toMap(LocateType::getCode, v -> v, (v1, v2) -> v2));
    private final Integer code;
    private final String desc;


    LocateType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static LocateType of(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return Optional
                .ofNullable(MAP.get(code))
                .orElse(null);
    }


    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }
}